package ModelLayer;
import java.util.ArrayList;


/**
 * a Container for the class Employee.
 * 
 * @author Team Black
 * @version 1.0
 */
public class EmployeeLibrary
{
    private ArrayList<Employee> employeeList;
    private static EmployeeLibrary instance;

    /**
     * Constructor for objects of class EmployeeLibrary
     */
    private EmployeeLibrary()
    {
        employeeList = new ArrayList<Employee>();
    }
     /**
     * makes the container singleton
     */
    public static EmployeeLibrary getInstance()
    {
        if(instance == null)
          {
               instance = new EmployeeLibrary();
          }
       return instance;
    }
    /**
     * adds an employee to the container
     */
    public void addEmployee(Employee _employee)
    {
        employeeList.add(_employee);
    }
    /**
     * removes an employee from the list of employees
     */
    public void removeEmployee(Employee _employee)
    {
        employeeList.remove(_employee);
    }
    /**
     * searh for an employee, by the Name
     */
    public Employee searchByName(String _name)
    {
        Employee retemployee = null;
        int index = 0;
        boolean found =false;
        
        while(index < employeeList.size() && !found)
        {
            Employee curremployee = employeeList.get(index);
            if(curremployee.getName().equalsIgnoreCase(_name))
            {
                retemployee = curremployee;
                found = true;
            }
            else
            {
                index++;
            }
        }
        return retemployee;
    }
    /**
     * search for an employee, by the id
     */
    public Employee searchById(int _id)
    {
        Employee retemployee = null;
        int index = 0;
        boolean found =false;
        
        while(index < employeeList.size() && !found)
        {
            Employee curremployee = employeeList.get(index);
            if(curremployee.getId() == _id)
            {
                retemployee = curremployee;
                found = true;
            }
            else
            {
                index++;
            }
        }
        return retemployee;
    }
    /**
     * returns a list of all employess, in the container.
     */
    public ArrayList<Employee> returnAllEmployee()
    {
        return employeeList;
    }
}
